package nc.ws.impl;

 
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import com.soa.eis.adapter.framework.message.IMsgObject;
import com.soa.eis.adapter.framework.message.impl.GroupRecord;
import com.soa.eis.adapter.framework.message.impl.MsgObject;
import com.soa.eis.adapter.framework.utils.log.LogUtil;

import groovy.util.NodeList;
 
 
/**
 * 测试uap到mes接口程序
 * @author Administrator
 *
 */
public class ZY_HTTP_By_URL_Visit_MES {

	public static void main(String[] args) throws Exception {
		@SuppressWarnings("unused")
		String mil=String.valueOf(System.currentTimeMillis());
		//String sHttpPost = "http://10.112.0.206:7080/httpservice";
		//http://10.112.0.206:7080/httpservice
		String sHttpPost = "http://10.112.0.206:7080/httpservice";
//		InputStream fi = new FileInputStream("./requestXML/getA.xml");
////		InputStream fi = new FileInputStream("./loginTCUA.xml");
//		byte[] reqMsg = new byte[fi.available()];
//		fi.read(reqMsg);
//		fi.close();
//		IMsgObject reqMo = new MsgObject(reqMsg, IMsgObject.MOType.initSR);
		// 定义请求报文对象
		/*<xs:element minOccurs="0" name="SerialNO" type="xs:string"/>
        <xs:element minOccurs="0" name="ServiceID" type="xs:string"/>
        <xs:element minOccurs="0" name="ServiceTime" type="xs:string"/>
        <xs:element minOccurs="0" name="SourceSysID" type="xs:string"/>
        <xs:element minOccurs="0" name="ServiceResponse" nillable="true" type="tns:servResp"/>*/
		IMsgObject reqMo = new MsgObject(IMsgObject.MOType.initSR);
		String SourceSysID = "06002";              //请求方(发布方) 系统号    OA  
	//	String ServiceID = "03002000000001"; //响应方(发布方) 服务号    MES
		String ServiceID = "06003000000001"; //响应方(发布方) 服务号    HR
		//获取系统时间
		Date date = new Date();
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
		String format = simpleDateFormat.format(date);
		//对请求报文对象进行设置
		reqMo.setSourceSysID(SourceSysID); //设置报文 请求方系统号      
		reqMo.setServiceID(ServiceID);     //设置报文 提供方服务号
//		System.currentTimeMillis();
		reqMo.setSerialNO(format.substring(0, 8)+SourceSysID+System.currentTimeMillis());//设置报文流水号,第三段表示今天发送的第几的一次报文
		reqMo.setServiceDateTime(format);  //设置报文 日期时间

	//	reqMo.setReqValue("string", "046878");
		reqMo.setReqValue("string", "000521");
		
	List<GroupRecord> grs1 = new ArrayList<GroupRecord>();
/////////////////带表名循环多条数据////////////////////////////////////////////////////////////////////		
		GroupRecord gr1 = new GroupRecord();
		gr1.setFieldValue("string","084655");
		/*gr1.setName("TableName");
		gr1.setFieldValue("FieldName1", "   151 2626    166    16 66   ");
		gr1.setFieldValue("FieldName2", "!@#$% %^&&**   *())__++ __)(    &amp;&amp;  ");
		gr1.setFieldValue("FieldName3", "name='b'");
		gr1.setFieldValue("FieldName4", "svasfbdfbsdfgv dfvb dsdcdv");
		gr1.setFieldValue("FieldName5", "中文  (*&&%$ @!/**-+;',.///\\.,.l;\\{}[]:?>><../; 字符");
		gr1.setFieldValue("FieldName6", "sdv中文字符dwvwcwq");
	
		
	
	
	
	
	
	
////================================================================================================		
		GroupRecord gr2 = new GroupRecord();
		gr2.setName("Import1");
		gr2.setFieldValue("MAKTX1", "气缸 MAL32*25-SDB");
		gr2.setFieldValue("MEINS", "EA");
		gr2.setFieldValue("GROES", "0201010190");
		gr2.setFieldValue("ZATR1", "MAL32*25-SDB");
		gr2.setFieldValue("ZATR5", "气缸");
	
//===============================================================================================
		GroupRecord gr3 = new GroupRecord();
		gr3.setName("Import6");
		gr3.setFieldValue("NEED2EXT", "X");
		gr3.setFieldValue("HIGH", "1076");*/

	
	
//===========================================================================
	//grs1.add(gr1);
//	grs1.add(gr2);	
	//grs1.add(gr3);
	
 	reqMo.setReqGroupRecord(grs1);
	
	//打印请求报文对象
//	LogUtil.getInstance().info(reqMo);
		
	System.out.println("Begin:1111111111111111111111111111111111111111111");
		System.out.println(reqMo);
	
		
		System.out.println("END!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
		IMsgObject respMo = null;
//		IServiceRequester  mt = new BaseServiceRequester();
 		
		//直接访问WSDL调用方法
		MYWSServiceRequester mt = new MYWSServiceRequester(sHttpPost);
		respMo = mt.execute(reqMo);
//		respMo=ZY_HTTP_By_URL_Visit_MES.execute(reqMo,sHttpPost);
		System.out.println(	"*****"+respMo );
		List<GroupRecord> record2 = respMo.getResGroupRecord("return") ;
		System.out.println(record2 == null ? "is null" : record2.size());
 		for (GroupRecord record : record2) {
			String fieldValue = record.getFieldValue("psnname");
//			String locator = record.getFieldValue("Name2");
			System.out.println(fieldValue);
//			System.out.println(locator);
 		}


	System.out.println(">>>>>>>>>>>>>>");
	//respMo.getResValue("Name") ;

 	//	System.out.println(">>>>>>>>>>>>>>"+a);
 		
		
//		System.out.println(respMo.toString());
		//LogUtil.getInstance().info(respMo);
		

		
		
		
		
		
		
	}
	
	 
	
	
	
}